home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #11 / Amiga Plus CD - 2004 - No. 11.iso / AmiSoft / Text / print / HPDJ400Src.lha / dospecial.c < prev    next >
C/C++ Source or Header  |  2004-05-23  |  8KB  |  240 lines

  1. /*
  2.  **************************************************************************
  3.  *
  4.  *       DoSpecial for HP_Deskjet_400C driver.
  5.  *       By PJ Hutchison 03/2/98
  6.  *
  7.  **************************************************************************
  8.  */
  9.  
  10. #include "global.h"
  11.  
  12. #define LPI             9    /* Position in init.. string from 0 - 7 */
  13. #define CPI             21
  14. #define QUALITY         37   /* New LP_DJ command moved to end of string */
  15. #define ASPECT          47   /* Portrait or Landscape */
  16. #define INIT_LEN        49
  17. #define LPP             10   /* Lines Per Page  */
  18. #define FORM_LEN        14
  19. #define LEFT_MARG       3
  20. #define RIGHT_MARG      10
  21. #define MARG_LEN        15
  22.  
  23. const char __ver[35] = "$VER: Deskjet_400C 40.17 (23.5.04)";
  24.  
  25. extern struct PrinterData *PD;
  26. extern struct PrinterExtendedData *PED;
  27.  
  28.  
  29. /* Routine to handle complex Escape sequences */
  30.  
  31. int DoSpecial(UWORD *command, char outputBuffer[], BYTE *vline, BYTE *currentVMI, BYTE *crlfFlag, UBYTE Parms[])
  32. {
  33.  
  34.         static UWORD textlength, topmargin;
  35.         int x, y, j, papersize, lpi;
  36.  
  37.         /* Initialise string:
  38.            NB: Colour text mode is not supported on HP 400s!
  39.            
  40.            00-05  \033&l26A   A4 paper
  41.            06-10  \033&l6D    6 lines per inch (LPI)
  42.            11-14  \033&d@     Turn off underline
  43.            15-19  \033(s0b    Bold off
  44.            20-22       10h    10 CPI
  45.            23-24        0p    Fixed spacing
  46.            25-26        0s    Upright style
  47.            27-29       12V    12/72 char height
  48.            30-33  \033(1E     UK Char Set
  49.            34-38  \033(s1Q    Quality (draft)
  50.            39-43  \033&l0O    Portrait orientation
  51.            44-48  \033(s3T    Courier Typeface
  52.         */
  53.         static char initThisPrinter[INIT_LEN + 1] =
  54.          "\033&l26A\033&l6D\033&d@\033(s0b10h0p0s12V\033(1E\033(s1Q\033&l0O\033(s3T";
  55.         
  56.         /* Top margin, text length */        
  57.         static char initForm[FORM_LEN + 1] = "\033&l000E\033&l000F";
  58.         /* Left, right margins */
  59.         static char initMarg[MARG_LEN + 1] = "\033&a000L\033&a000M\015";
  60.         static char initTMarg[] = "\033&l000E\033&l000F";
  61.  
  62.         x = y = j = 0;
  63.  
  64.         if (*command == aRIN) {         /* Initialise command */
  65.                 while(x < INIT_LEN) {
  66.                         outputBuffer[x] = initThisPrinter[x];
  67.                         x++;
  68.                 }
  69.                 outputBuffer[x++] = '\015'; /* CR */
  70.  
  71.                 lpi = 6;
  72.                 if (PD->pd_Preferences.PrintSpacing == EIGHT_LPI) {
  73.                         outputBuffer[LPI] = '8';
  74.                         lpi = 8;
  75.                 }
  76.  
  77.                 if (PD->pd_Preferences.PrintPitch == ELITE) {
  78.                         outputBuffer[CPI] = '2';
  79.                 }
  80.                 else if (PD->pd_Preferences.PrintPitch == FINE) {
  81.                         outputBuffer[CPI] = '5';
  82.                 }
  83.  
  84.                 if (PD->pd_Preferences.PrintQuality == LETTER) {
  85.                         outputBuffer[QUALITY] = '2';
  86.                 }
  87.                 /* Change to Landscape (Vert)) if selected) */
  88.                 if (PD->pd_Preferences.PrintAspect == ASPECT_VERT) {
  89.                             outputBuffer[ASPECT] = '1';
  90.                 }
  91.  
  92.                 j = x; /* set the formlength = textlength, top margin = 0 */
  93.                 papersize = PD->pd_Preferences.PaperSize;
  94.         switch (papersize) 
  95.         {
  96.            case US_LETTER:
  97.             papersize = 10 * lpi;
  98.             break;
  99.            case US_LEGAL:
  100.             papersize = 13 * lpi;
  101.             break;
  102.            case EURO_A4:
  103.             papersize = (lpi == 8 ? 85 : 65);
  104.             break;
  105.            default:   /* Custom size */
  106.             papersize = PD->pd_Preferences.PaperLength;
  107.         }
  108.                 textlength = papersize;
  109.                 topmargin = 0;
  110.  
  111.                 while (y < FORM_LEN) {
  112.                         outputBuffer[x++] = initForm[y++];
  113.                 }
  114.                 numberString(textlength, j + LPP, outputBuffer);
  115.  
  116.                 Parms[0] = PD->pd_Preferences.PrintLeftMargin;
  117.                 Parms[1] = PD->pd_Preferences.PrintRightMargin;
  118.                 *command = aSLRM;
  119.         }
  120.  
  121.         if (*command == aSLRM) {        /* L&R Margins */
  122.                 j = x;
  123.                 y = 0;
  124.                 while(y < MARG_LEN) {
  125.                         outputBuffer[x++] = initMarg[y++];
  126.                 }
  127.                 numberString(Parms[0] - 1, j + LEFT_MARG, outputBuffer);
  128.                 numberString(Parms[1] - 1, j + RIGHT_MARG, outputBuffer);
  129.                 return(x);
  130.         }
  131.  
  132.  
  133.         if(*command == aSUS0) {              /* Normalise the line */
  134.                 if (*vline > 0) {
  135.                         *command = aPLD;
  136.                 }
  137.                 if (*vline < 0) {
  138.                         *command = aPLU;
  139.                 }
  140.                 *vline = 0;
  141.                 return(0);
  142.         }
  143.  
  144.         if (*command == aPLU) {
  145.                 (*vline)++;
  146.                 return(0);
  147.         }
  148.  
  149.         if (*command == aPLD){
  150.                 (*vline)--;
  151.                 return(0);
  152.         }
  153.  
  154.         if (*command == aSTBM) {        /* Top & bottom margins */
  155.                 if (Parms[0] == 0) {
  156.                         Parms[0] = topmargin;
  157.                 }
  158.                 else {
  159.                         topmargin = --Parms[0];
  160.                 }
  161.  
  162.                 if (Parms[1] == 0) {
  163.                         Parms[1] = textlength;
  164.                 }
  165.                 else {
  166.                         textlength=Parms[1];
  167.                 }
  168.                 while (x < 13) {
  169.                         outputBuffer[x] = initTMarg[x];
  170.                         x++;
  171.                 }
  172.                 numberString(Parms[0], 3, outputBuffer);
  173.                 numberString(Parms[1] - Parms[0], 10, outputBuffer);
  174.                 return(x);
  175.         }
  176.  
  177.         if (*command == aSLPP) {        /* Set form length */
  178.                 while(x < FORM_LEN) {
  179.                         outputBuffer[x] = initForm[x];
  180.                         x++;
  181.                 }
  182.                 /*restore textlength, margin*/
  183.                 numberString(topmargin, 3, outputBuffer);
  184.                 numberString(textlength, 10, outputBuffer);
  185.                 return(x);
  186.         }
  187.  
  188.         if (*command == aRIS) {         /* Reset */
  189.                 PD->pd_PWaitEnabled = 253;   /* Save data! */
  190.         }
  191.  
  192.         return(0);
  193. }
  194.  
  195. /* Inserts Param into output buffer */
  196. void numberString(UBYTE Param, int x, char outputBuffer[])
  197. {
  198.         if (Param > 199) {
  199.                 outputBuffer[x++] = '2';
  200.                 Param -= 200;
  201.         }
  202.         else if (Param > 99) {
  203.                 outputBuffer[x++] = '1';
  204.                 Param -= 100;
  205.         }
  206.         else {
  207.                 outputBuffer[x++] = '0'; /* always return 3 digits */
  208.         }
  209.  
  210.         if (Param > 9) {
  211.                 outputBuffer[x++] = Param / 10 + '0';
  212.         }
  213.         else {
  214.                 outputBuffer[x++] = '0';
  215.         }
  216.  
  217.         outputBuffer[x] = Param % 10 + '0';
  218. }
  219.  
  220. /* Following functions are refered via printertag.asm */
  221.    
  222. int ConvFunc(char *buf, char c, int flag)
  223. /* expand lf into lf/cr flag (0-yes, else no ) */
  224. {
  225.         if (c == '\014') { /* if formfeed (page eject) */
  226.                 PED->ped_PrintMode = 0; /* no data to print */
  227.         }
  228.         return(-1); /* pass all chars back to the printer device */
  229. }
  230.  
  231. int Close(union printerIO *ior)
  232. {
  233.         if (PED->ped_PrintMode) { /* if data has been printed */
  234.                 (*(PD->pd_PWrite))("\014",1); /* eject page */
  235.                 (*(PD->pd_PBothReady))(); /* wait for it to finish */
  236.                 PED->ped_PrintMode = 0; /* no data to print */
  237.         }
  238.         return(0);
  239. }
  240.